/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.cloud.base.util.expression;

import fr.expression4j.core.Expression;
import fr.expression4j.core.Parameters;
import fr.expression4j.core.exception.EvalException;
import fr.expression4j.core.exception.ParsingException;
import fr.expression4j.factory.ExpressionFactory;
import fr.expression4j.factory.NumberFactory;
/**
 * @project-name:standard-cloud
 * @package-name:com.hyts.cloud.base.util.expression
 * @author:LiBo/Alex
 * @create-date:2020-06-29 21:48
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class TestAgregated {

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            Expression exp1 = ExpressionFactory.createExpression("f1(x)=x*x");
            Expression exp2 = ExpressionFactory.createExpression("f2(b,a,c)=f1(b)-4*a*c");
            Parameters params = ExpressionFactory.createParameters();
            params.addParameter("b", NumberFactory.createReal(4));
            params.addParameter("a", NumberFactory.createReal(2));
            params.addParameter("c", NumberFactory.createReal(2));
            double val = exp2.evaluate(params).getRealValue();
            System.out.println("exp2 name:" + exp2.getName());
            System.out.println("exp2:" + exp2);
            System.out.println("exp2 result:" + val);
        } catch (ParsingException e) {
            e.printStackTrace();
        } catch (EvalException e) {
            e.printStackTrace();
        }
    }
}
